package com.sf.sms.software.service.impl;

import com.sf.sms.software.dao.SoftwareCategoryMapper;
import com.sf.sms.software.entity.SoftwareCategory;
import com.sf.sms.software.entity.dto.SoftwareCategoryDTO;
import com.sf.sms.software.service.SoftwareCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SoftwareCategoryServiceImpl implements SoftwareCategoryService {

	@Autowired
    SoftwareCategoryMapper softwareCategoryMapper;

	@Override
	public void addSoftwareCategory(SoftwareCategory softwarecategory) {
		softwareCategoryMapper.addSoftwareCategory(softwarecategory);
	}

	@Override
	public List<SoftwareCategoryDTO> getAllSoftwareCategory() {
		List<SoftwareCategoryDTO> result = new ArrayList<SoftwareCategoryDTO>();
		List<SoftwareCategory> list = softwareCategoryMapper.getAll();
		for ( SoftwareCategory sc : list ) {
			SoftwareCategoryDTO scDTO = new SoftwareCategoryDTO();
			scDTO.setId(sc.getId());
			scDTO.setName(sc.getName());

			result.add(scDTO);
		}
		return result;
	}
}
